package cn.stylefeng.guns.modular.order.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;

import cn.stylefeng.guns.modular.order.entity.WhOutOrderDetailed;
import cn.stylefeng.guns.modular.order.mapper.WhOutOrderDetailedMapper;
import cn.stylefeng.guns.modular.order.model.params.WhOutOrderDetailedParam;
import cn.stylefeng.guns.modular.order.model.result.WhOutOrderDetailedResult;
import cn.stylefeng.guns.modular.order.service.WhOutOrderDetailedService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 武汉出库订单明细表 服务实现类
 * </p>
 *
 * @author wp
 * @since 2025-09-30
 */
@Service
public class WhOutOrderDetailedServiceImpl extends ServiceImpl<WhOutOrderDetailedMapper, WhOutOrderDetailed> implements WhOutOrderDetailedService {

    @Override
    public void add(WhOutOrderDetailedParam param){
        WhOutOrderDetailed entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(WhOutOrderDetailedParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(WhOutOrderDetailedParam param){
        WhOutOrderDetailed oldEntity = getOldEntity(param);
        WhOutOrderDetailed newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public WhOutOrderDetailedResult findBySpec(WhOutOrderDetailedParam param){
        return null;
    }

    @Override
    public List<WhOutOrderDetailedResult> findListBySpec(WhOutOrderDetailedParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(WhOutOrderDetailedParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public void saveBatchList(List<WhOutOrderDetailedParam> list) {
        baseMapper.saveBatchList(list);
    }

    private Serializable getKey(WhOutOrderDetailedParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private WhOutOrderDetailed getOldEntity(WhOutOrderDetailedParam param) {
        return this.getById(getKey(param));
    }

    private WhOutOrderDetailed getEntity(WhOutOrderDetailedParam param) {
        WhOutOrderDetailed entity = new WhOutOrderDetailed();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
